package com.yuzhi.master.drainAlarmRule.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuzhi.common.core.mapper.BaseMapperPlus;
import com.yuzhi.master.drainAlarmRule.domain.DrainAlarmRule;
import com.yuzhi.master.drainAlarmRule.domain.vo.DrainAlarmRuleVo;
import com.yuzhi.master.drainEvents.domain.vo.DataDictionary;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DrainAlarmRuleMapper extends BaseMapperPlus<DrainAlarmRuleMapper, DrainAlarmRule, DrainAlarmRuleVo> {

    Page<DrainAlarmRuleVo> selectPageList(
            @Param("page") Page<DrainAlarmRuleVo> page,
            @Param("ew") Wrapper<DrainAlarmRule> queryWrapper
    );

    DrainAlarmRuleVo queryById(@Param("id") String id);

    /**
     * 从视图查询original_id和name用于设备ID映射
     * 假设视图名称为drain_app_view
     */
    @Select("SELECT original_id, name FROM psbiz.drain_app_view")
    List<Map<String, String>> queryOriginalIdAndNameFromView();

    /**
     * 查询报警规则字典
     *
     * @param dictType 字典类型
     * @return 字典列表
     */
    @Select("SELECT DISTINCT dd.dict_label AS dictLabel, dd.dict_value AS dictValue, dd.dict_sort FROM psbiz.sys_dict_data dd WHERE dd.dict_type = 'alarm_rule_type' AND dd.deleted = 0 ORDER BY dd.dict_sort ASC")
    List<DataDictionary> alarmRuleDictionary(String dictType);
}
